package edu.mta.pokerstats;

public class LoginHandler
{
	public static ELoginStaus isLoginValid(String i_Username, String i_passwod)
	{
		ELoginStaus returnValue = ELoginStaus.OK;
		if (isUsernameValid(i_Username))
		{
			if (!isPasswordValid(i_Username, i_passwod))
			{
				returnValue = ELoginStaus.BAD_PASSWORD;
			}
		}
		else
		{
			returnValue = ELoginStaus.BAD_USERNAME;
		}
		
		return returnValue;
	}

	public static boolean isUsernameValid(String i_Username)
	{
		boolean returnValue = false;
		Player player = Player.getPlayerByUsername(i_Username);
		if (player != null)
		{
			returnValue = true;
		}
		return returnValue;
	}

	public static boolean isPasswordValid(String i_Username, String i_passwod)
	{
		boolean returnValue = false;
		Player player = Player.getPlayerByUsername(i_Username);
		if (player != null && player.getPassword() != null)
		{
			returnValue = player.getPassword().equals(i_passwod);
		}
		
		return returnValue;
	}

	public enum ELoginStaus
	{
		OK, BAD_PASSWORD, BAD_USERNAME
	}
}
